import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:jverify/jverify.dart';

void main() {
  const MethodChannel channel = MethodChannel('jverify');
  final Jverify jverify = new Jverify();

  TestWidgetsFlutterBinding.ensureInitialized();

  setUp(() {
    channel.setMockMethodCallHandler((MethodCall methodCall) async {
      switch (methodCall.method) {
        case 'checkVerifyEnable':
            return {'result': true, 'extra': {'operatorType': 'CM'}};
          case 'isInitSuccess':
            return {'result': true};
          case 'getToken':
            return {'code': 2000, 'message': 'mock_token'};
        default:
          return null;
      }
    });
  });

  tearDown(() {
    channel.setMockMethodCallHandler(null);
  });

  test('checkVerifyEnable', () async {
    final result = await jverify.checkVerifyEnable();
    expect(result['result'], isTrue);
  });
  test('isInitSuccess', () async {
    final result = await jverify.isInitSuccess();
    expect(result['result'], isTrue);
  });
  test('getToken', () async {
    final result = await jverify.getToken();
    expect(result['message'], isNotNull);
  });
}

